package cn.xfdzx.android.apps.shop.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;

import butterknife.BindView;
import butterknife.OnClick;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.base.BaseMvpActivity;

public class SearchDefultActivity extends BaseMvpActivity {

    @BindView(R.id.et_search_default)
    EditText etSearchDefault;
    @BindView(R.id.iv_search_et_delete)
    ImageView ivHomeSearchEtDelete;

    @Override
    public int getLayoutId() {
        return R.layout.activity_search_defult;
    }

    @Override
    public void initView() {
        etSearchDefault.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                if (s.toString().trim().length() == 0){
                    ivHomeSearchEtDelete.setVisibility(View.VISIBLE);
                }else {
                    ivHomeSearchEtDelete.setVisibility(View.VISIBLE);
                }
            }
        });
    }

    @Override
    public void showLoading() {

    }

    @Override
    public void hideLoading() {

    }

    @Override
    public void onError(Throwable throwable) {

    }

    @OnClick({R.id.iv_home_back, R.id.tv_home_search, R.id.iv_search_et_delete})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_search_et_delete:
                etSearchDefault.getText().clear();
                break;
         case R.id.iv_home_back:
                finish();
                break;
            case R.id.tv_home_search:
                Intent intent=new Intent();
                intent.putExtra("key",etSearchDefault.getText().toString().trim());
                setResult(RESULT_OK,intent);
                finish();
                break;
        }
    }
}
